from OS import *
from Program import *
from CPUInstruction import *
from multiprocessing import Queue
from IOInstructionPrinter import *
from IOInstructionScreen import *
from IOInstructionKeyBoard import *  
from ManagerCPU import CPUManager

class MyOSfactory(object):
    
    def __init__(self):
        '''
        Constructor
        '''
    

    def setUp(self):
    
        self.outputQueue = Queue()
    
        self.scheduler = Priority()
        
        rm = ResourceManager()
        rm.registerResource("kb", 1, self.scheduler.readyQueue, self.outputQueue)
        rm.registerResource("screen", 1, self.scheduler.readyQueue, self.outputQueue)
        rm.registerResource("printer", 1, self.scheduler.readyQueue, self.outputQueue)
        
        cpuManager = CPUManager(1, rm,self.outputQueue,self.scheduler)
       
        myOS = OS(self.scheduler, rm,cpuManager, self.outputQueue)
        myProg = Program()
        myProg.setPriority(1)
        myProg2 = Program()
        myProg3 = Program()
        myProg2.setPriority(2)
        in11=CPUInstruction(1,"cpu prog2")
        in1=CPUInstruction(1,"cpu prog")
        in3=IOInstructionPrinter(3,"printer") 
        in5=IOInstructionScreen(2,"screen")
        in6=IOInstructionKeyBoard(2,"kb")
        
        myProg.addInstruction(in1)
        myProg.addInstruction(in1)
        myProg.addInstruction(in5)
        myProg.addInstruction(in1)
        myProg.addInstruction(in5)
        myProg.addInstruction(in1)
        myProg.addInstruction(in3)
        
        myProg2.addInstruction(in6)
        myProg2.addInstruction(in11)
        
        #myOS.addProgram(myProg)
        myOS.addProgram(myProg2)
        
        myOS.startUP()
        time.sleep(15)
        myOS.shutDown()

